fix: isolate concurrent builds via build_id namespace on git resources#2
Merged
fix: isolate concurrent builds via build_id namespace on git resources#2
Conversation
When two build() calls run simultaneously on the same repository, they
collide on shared git resources: the integration branch (feature/<slug>)
and issue branches/worktrees (issue/<NN>-<name>). The workspace setup
agent even deletes existing branches when they conflict, silently
destroying the other build's in-progress work.
Fix: generate a short build_id (8 hex chars) at the start of build() and
thread it through the entire pipeline so all per-build git resources are
uniquely namespaced:
- Integration branch: feature/<build_id>-<goal-slug>
- Issue branches: issue/<build_id>-<NN>-<name>
- Worktree dirs: .worktrees/issue-<build_id>-<NN>-<name>/
The cleanup path derivation (branch.replace("/", "-")) continues to map
correctly to worktree directories because setup and cleanup use the same
naming convention.
All new parameters default to "" for backward compatibility — builds
that call execute() directly without a build_id fall back to the
existing naming convention with no regressions.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Two bugs in the original implementation: 1. Per-level cleanup (dag_executor.py ~1154) derived branch names as `issue/<NN>-<name>` without build_id, so it tried to delete branches that didn't exist (build_id-namespaced builds create `issue/<bid>-<NN>-<name>`). Prefer `branch_name` already injected by _setup_worktrees; fall back to build_id-prefixed derivation otherwise. 2. Final cleanup sweep (dag_executor.py ~1333) had the same bug when constructing the list from dag_state.all_issues. Also tighten the workspace SETUP_SYSTEM_PROMPT to explicitly document both the plain and Build-ID-prefixed command formats and instruct the agent to always follow the task's specified format. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
build()calls on the same repository collide on shared git resources (integration branch, issue branches, worktree dirs), with the second build silently destroying the first's in-progress workbuild_id(8 hex chars) at the start ofbuild()and thread it through the pipeline so all per-build git resources are uniquely namespaced""— fully backward compatibleWhat Was Broken
When two builds run simultaneously on the same repo, they share:
feature/<goal-slug>: second build fails or hijacks the first's branchissue/<NN>-<name>: workspace setup agent explicitly deletes existing branches before recreating, silently destroying the other build's committed work.worktrees/issue-<NN>-<name>/: same filesystem collisionChanges Made
All git resources are now namespaced by
build_id:feature/<build_id>-<goal-slug>issue/<build_id>-<NN>-<name>.worktrees/issue-<build_id>-<NN>-<name>/The cleanup path derivation (
branch.replace("/", "-")) continues to map correctly to worktree directories since setup and cleanup use the same convention.Files changed:
swe_af/app.py— generatebuild_id, pass torun_git_initandexecute()swe_af/execution/dag_executor.py— threadbuild_idthroughrun_dag(),_init_dag_state(),_setup_worktrees()swe_af/execution/schemas.py— addbuild_idfield toDAGStateswe_af/prompts/git_init.py— instruct agent to usefeature/<build_id>-<goal-slug>swe_af/prompts/workspace.py— instruct agent to useissue/<build_id>-<NN>-<name>branch/dir namesswe_af/reasoners/execution_agents.py— passbuild_idtogit_init_task_promptandworkspace_setup_task_promptTest Plan
issue/abc12345-01-namevsissue/def67890-01-name)execute()called directly withoutbuild_idfalls back to old naming🤖 Generated with Claude Code